package com.lj.graduate.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lj.graduate.entity.Commodity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.lj.graduate.service.IScenicDetailService;
import com.lj.graduate.entity.ScenicDetail;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ljy
 * @since 2023-03-23
 */
@RestController
@RequestMapping("/scenic")
public class ScenicDetailController {

    @Resource
    private IScenicDetailService scenicDetailService;

    // 新增或者更新
    @PostMapping
    public boolean save(@RequestBody ScenicDetail scenicDetail) {
        return scenicDetailService.saveOrUpdate(scenicDetail);
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return scenicDetailService.removeById(id);
    }

    @PostMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<Integer> ids) {
        return scenicDetailService.removeByIds(ids);
    }

    @GetMapping
    public List<ScenicDetail> findAll() {
        return scenicDetailService.list();
    }

    @GetMapping("/{id}")
    public ScenicDetail findOne(@PathVariable Integer id) {
        return scenicDetailService.getById(id);
    }

    @GetMapping("/page")
    public IPage<ScenicDetail> findPage(@RequestParam Integer pageNum,
                                       @RequestParam Integer pageSize,
                                       @RequestParam(defaultValue = "") String level) {
        IPage<ScenicDetail> page = new Page<>(pageNum, pageSize);
        QueryWrapper<ScenicDetail> queryWrapper = new QueryWrapper<>();
        if (!"".equals(level)) {
            queryWrapper.like("level", level);
        }
//        queryWrapper.orderByDesc("id");
        return scenicDetailService.page(new Page<>(pageNum, pageSize), queryWrapper);

    }


}

